"""
    封装汽车出租模块
"""
from car_rental.baw import login
from car_rental.caw.base_request import BaseRequest


def init_rent_from(url, test_request, cs):
    """
    初始化组车单
    :param url: 测试环境
    :param test_request: BaseRequests的实例
    :param cs: 测试数据
    :return: 登陆接口的响应
    """
    url =url + "/carRental/rent/initRentFrom.action"
    r = test_request.get(url, params=cs)
    return r

def save_Rent(url, test_request, cs):
    """
    保存租车单
    :param url: 测试环境
    :param test_request: BaseRequests的实例
    :param cs: 测试数据
    :return: 保存租车单接口的响应
    """
    url = url + "/carRental/rent/saveRent.action"
    hd = {
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"

    }
    r = test_request.post(url, headers=hd, data=cs)
    return r

if __name__ == '__main__':
    url = "http://192.168.73.129:8080"
    test_request = BaseRequest()
    login.login(url, test_request, {"loginname": "admin",
                                    "pwd": "123456"})
    # 测试初始化接口
    init_cs ={
        "identity": "360421199908162526",
        "price": "2500",
        "carnumber": "赣G5634E1"
    }
    r = init_rent_from(url, test_request, init_cs)
    print(r)
    rentid = r.json()["rentid"]
    print(rentid)
    begindate = r.json()["begindate"]
    opernam = r.json()["opername"]
    # 测试保存接口
    save_cs = {
        "rentid": rentid,
        "begindate": begindate,
        "returndate": "2022-05-13 01:59:24",
        "identity": init_cs["identity"],
        "carnumber": init_cs["carnumber"],
        "price": init_cs["price"],
        "opername": opernam
    }
    save_Rent(url, test_request, save_cs)